package gold.digger;

import gold.utils.InputUtil;
import gold.vo.TreeNode;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1305 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        int INF = 0x3f3f3f3f;

        public List<Integer> getAllElements(TreeNode root1, TreeNode root2) {
            List<Integer> ans = new ArrayList<>();
            List<Integer> l1 = new ArrayList<>(), l2 = new ArrayList<>();
            dfs(root1, l1);
            dfs(root2, l2);
            int n = l1.size(), m = l2.size(), i = 0, j = 0;
            while (i < n || j < m) {
                int a = i < n ? l1.get(i) : INF, b = j < m ? l2.get(j) : INF;
                if (a <= b) {
                    ans.add(a);
                    i++;
                } else {
                    ans.add(b);
                    j++;
                }
            }
            return ans;
        }

        void dfs(TreeNode root, List<Integer> list) {
            if (root == null) return;
            dfs(root.left, list);
            list.add(root.val);
            dfs(root.right, list);
        }
    }


    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Solution().toString());
    }

    public static void main(String[] args) throws Exception {
        LC1305 an = new LC1305();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
